package cn.com.self.apis.portal.controller;

import cn.com.self.apis.escrow.entity.EscrowAmountChange;
import cn.com.self.apis.escrow.service.impl.EscrowAmountChangeImpl;
import cn.com.selfsoft.smartcity.commons.http.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author Eric.Chen
 * @Date 2021/6/20 16:24
 */
@Controller
@RequestMapping("/api/v1/escrow-amount-change")
@Api(tags = "托管预算增加申请类")
public class EscrowAmountChangeController {

    @Autowired
    EscrowAmountChangeImpl escrowAmountChange;

    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "新增托管预算增加申请")
    @Transactional
    public ResponseEntity create(@RequestBody EscrowAmountChange entity, HttpServletRequest request) {
        EscrowAmountChange amountChange = escrowAmountChange.createAmountChange(entity);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(amountChange));
    }

    @ApiOperation(value = "获取托管预算增加申请")
    @RequestMapping(value = {"/load/{id}"}, method = RequestMethod.GET)
    @ResponseBody
    public ResponseEntity loadEscrowInfo(@PathVariable("id") String id, HttpServletRequest request) {
        EscrowAmountChange escrowAmountChange = this.escrowAmountChange.loadAmountChangeInfoById(id);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(escrowAmountChange));
    }

    @PostMapping(value = "/update/{id}")
    @ApiOperation(value = "更新获取托管预算增加申请")
    public ResponseEntity update(@PathVariable("id") String id, @RequestBody EscrowAmountChange entity) {
        EscrowAmountChange escrowAmountChange = this.escrowAmountChange.updateAmountChange(id, entity);
        return ResponseEntity.status(HttpStatus.OK).body(new ResultModel<>(escrowAmountChange));
    }

}
